package tankGame05.window;

import tankGame05.Recorder;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-03-31
 * Time:16:33
 */
@SuppressWarnings("all")
public class MyFrame{
    JFrame frame = null;
    MyPanel panel = null;
    JButton button1, button2;
    static boolean isNewClicked = false;
    static boolean isContinueClicked = false;
    public MyFrame(){
        frame = new JFrame();
        panel = new MyPanel();
        frame.setSize(1230,817);
        setButtons();
        panel.setLayout(null);
        panel.add(button1);
        panel.add(button2);
        frame.addKeyListener(panel);
        new Thread(panel).start();
        frame.add(panel);
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                Recorder.recordData();
            }
        });
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    public void setButtons(){
        isNewClicked = false;
        isContinueClicked = false;
        button1 = new JButton("开始游戏");
        button2 = new JButton("继续游戏");
        button1.setBounds(450,500,100,40);
        button2.setBounds(690,500,100,40);
        button1.addActionListener(e -> {
            isNewClicked = true;
            panel.remove(button1);
            panel.remove(button2);
            frame.requestFocus();
        });
        button2.addActionListener(e -> {
            isContinueClicked = true;
            panel.remove(button1);
            panel.remove(button2);
            frame.requestFocus();
        });
    }
}
